/*
 * Diego Zamboni Latance 			344990
 * Fellipe Augusto Ruiz de Souza 	344796
 * 
 */
package ast;

import java.util.ArrayList;
import lexer.Symbol;

public class Method {
	private String ident;
	private Type type;
	private int qualifier;
	private ParamList parameters;
	private ArrayList<Statement> body;

	public Method(String ident, Type type, int qualifier) {
		this.ident = ident;
		this.type = type;
		this.qualifier = qualifier;
		this.parameters = new ParamList();
		this.body = new ArrayList<Statement>();
	}

	public String getIdent() {
		return ident;
	}

	public void setIdent(String ident) {
		this.ident = ident;
	}

	public ParamList getParameters() {
		return parameters;
	}

	public void setParameters(ParamList parameters) {
		this.parameters = parameters;
	}

	public int getQualifier() {
		return qualifier;
	}

	public void setQualifier(int qualifier) {
		this.qualifier = qualifier;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public ArrayList<Statement> getBody() {
		return body;
	}

	public void setBody(ArrayList<Statement> body) {
		this.body = body;
	}

	public void genKrakatoa(PW pw) {
		switch (qualifier) {
		case Symbol.PUBLIC:
			pw.printIdent("public ");
			break;
		case Symbol.PRIVATE:
			pw.printIdent("private ");
			break;
		case Symbol.STATICPUBLIC:
			pw.printIdent("static public ");
			break;
		case Symbol.STATICPRIVATE:
			pw.printIdent("static public ");
			break;
		}
		pw.print(this.getType().getKrakatoaName() + " " + ident + " ( ");
		if (parameters != null)
			parameters.genKrakatoa(pw);
		pw.print("){\n");
		pw.add();
		for (int i = 0; i < body.size(); i++) {
			body.get(i).genKrakatoa(pw);
		}
		pw.sub();
		pw.printIdent("}\n");
	}
}